//
// Created by jinbang.li on 2023/4/9.
//

#include "OpThread.h"
#include <thread>
using namespace std;
void sleep_thread(int millseconds){
    chrono::milliseconds  du(millseconds);
    this_thread::sleep_for(du);
}
bool OpThread::Start() {
    isExit = false;
   thread th(&OpThread::ThreadMain, this);
   th.detach();
    return true;//native模块记得函数有返回值的一定返回
}
void OpThread::ThreadMain () {
    isRunning = true;
    Main();
    isRunning = false;
}
void OpThread::Stop() {
    isExit = true;
    for (int i = 0;i < 100;i++) {
        if (!isRunning){
            return;
        }
        sleep_thread(1);
    }
}